HackerRank Red John is Back
code: python
import math
import os
import random
import re
import sys
#
# Complete the 'redJohn' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER n as parameter.
#
def redJohn(n):
# Write your code here
# 4
res = n % 4
MAX_N = 10 ** 6
is_prime = True * (MAX_N + 1) def sieve(n):
p = 0
for i in range(n + 1):
is_prime0 = is_prime1 = False for i in range(2, n + 1):
p += 1
for j in range(2 * i, n + 1, i):
return p
return sieve(res)
if __name__ == '__main__':
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
result = redJohn(n)
fptr.write(str(result) + '\n')
fptr.close()
解答
code: python
import math
import os
import random
import re
import sys
#
# Complete the 'redJohn' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER n as parameter.
#
def sito(n=300000):
primes = []
for i in range(2, n):
primes.append(i)
j = i+i
while j < n:
j += i
return primes
PRIMES = sito()
# print(PRIMES) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47...
def redJohn(n):
# Write your code here
for i in range(5, n+1):
return 0
i = 0
while i < len(PRIMES):
return i
i += 1
return int(round(resn / math.log(resn))) if __name__ == '__main__':
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
result = redJohn(n)
fptr.write(str(result) + '\n')
fptr.close()
テーマ
メモ
https://www.youtube.com/watch?v=yxz2ng_YvBA
https://scrapbox.io/files/61d2c6b228002b0021321575.png